// Called from entry.S to get us going.
// entry.S already took care of defining envs, pages, uvpd, and uvpt.

#include <inc/lib.h>

extern void umain(int argc, char **argv);

const volatile struct Env *thisenv;
const char *binaryname = "<unknown>";

void
libmain(int argc, char **argv)
{
	// set thisenv to point at our Env structure in envs[].
	// LAB 3: Your code here.
	//目前在用户态，只能通过系统调用获得环境id
	envid_t env_id = sys_getenvid();
	cprintf("env_id:%08x\n",env_id);
	//通过环境id来获取对应环境引用，因在用户态，不可使用envid2env
	thisenv = &envs[ENVX(env_id)];
	// uint32_t res = envid2env(env_id,&thisenv,1);
	// if(res!=0){
	// 	cprintf("Failed to map envid to env!:%e",res);
	// }
	// save the name of the program so that panic() can use it
	if (argc > 0)
		binaryname = argv[0];

	// call user main routine
	umain(argc, argv);

	// exit gracefully
	exit();
}

